home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 35 / Amiga Format AFCD35 (Issue 119, Jan 1999).iso / -in_the_mag- / reader_requests / fredobbutils / bbsrc / searchilbm10.s < prev    next >
Text File  |  1998-11-06  |  7KB  |  316 lines

  1. *** IFF-ILBM Ripper V1.0 bootblock ***
  2. *
  3. * Coded by Frédéric BASSALER (April '96)
  4. *
  5. * Cherche des données IFF-ILBM dans la mémoire
  6. * et sauve les images les unes à la suite des autres
  7. * sur un disque (avec le trackdisk.device).
  8. * Il faut ensuite utiliser l'utilitaire PicRestore (inclus) pour récupérer
  9. * ces images sous forme de fichiers.
  10. *
  11. * Special bootblock: finds IFF-ILBM pictures in memory
  12. * and writes them onto disk (in trackload format, no DOS!).
  13. * Use the supplied utility 'PicRestore' in order to obtain the files from
  14. * the disk.
  15.  
  16.     incdir    asm:/Include/
  17.     include    equ.s
  18.     include    exec/types.i
  19.     include    exec/memory.i
  20.     include    exec/execbase.i
  21.  
  22.     rsreset
  23. ioreq    rs.l    1
  24. lomem    rs.l    1
  25. himem    rs.l    1
  26. intbase    rs.l    1
  27. piclen    rs.l    1
  28. lastadr    rs.l    1
  29. lastblk    rs.l    1
  30. hashbuf    rs.l    1
  31. numpics    rs.w    1
  32. VARSIZE    rs.w    0
  33.  
  34. ;uncomment this to run in debug mode (that is, to test the program
  35. ;from AsmOne)
  36.  
  37. ;DBUG=0
  38.  
  39. ;Start of bootblock
  40. Start:
  41.     IFND    DBUG
  42.     dc.b    "DOS",0        ;replace 0 by 1 for FFS
  43.     dc.l    0,$370        ;sum, rootblock
  44.     ENDC
  45. ;Start of bootblock code
  46. Main:
  47.     IFD    DBUG
  48.     move.l    4.w,a6
  49.     ENDC
  50.  
  51.     movem.l    d0-a6,-(sp)    ;save regs
  52.     lea    -VARSIZE(sp),sp    ;allocate variables onto the stack
  53.     move.l    sp,a5        ;variable base address is in A5
  54.  
  55.     IFND    DBUG
  56.     move.l    a1,ioreq(a5)
  57.     ELSE            ;debug mode: open trackdisk unit 0
  58.     lea    tdport(pc),a1
  59.     move.l    a1,-(sp)
  60.     move.l    4.w,a6
  61.     move.l    ThisTask(a6),$10(a1)
  62.     jsr    AddPort(a6)
  63.     lea    tdreq(pc),a1
  64.     move.l    a1,ioreq(a5)
  65.     move.l    (sp)+,14(a1)
  66.     lea    trackname(pc),a0
  67.     moveq    #0,d0        ;unit=0    (DF0)
  68.     moveq    #0,d1        ;flags: no
  69.     jsr    OpenDevice(a6)
  70.     ENDC
  71.  
  72.     clr.l    hashbuf(a5)
  73.     bsr.w    MotOff        ;turn drive's motor off
  74.  
  75.     lea    intname(pc),a1
  76.     jsr    OldOpenLibrary(a6)
  77.     move.l    d0,intbase(a5)
  78.  
  79.     lea    alert.txt(pc),a0
  80.     bsr.w    MyAlert        ;show 'alert' message
  81.     beq.w    xit
  82.  
  83. * begin the search
  84.  
  85. .search
  86.     clr    numpics(a5)
  87.     moveq    #3,d0        ;bloc de départ de sauvegarde des images
  88.     move.l    d0,lastblk(a5)    ;(le bloc 2 sert de Hash table)
  89.     move.l    #512,d0        ;1 bloc
  90.     move.l    #$10002,d1    ;chip+clear
  91.     jsr    AllocMem(a6)
  92.     move.l    d0,hashbuf(a5)
  93.     beq.s    .err
  94.     move.l    d0,a3
  95. ;put header
  96.     move.l    #'PICS',(a3)+    ;Identificateur
  97.     clr    (a3)+
  98.  
  99. * rechercher des images dans toutes les zones mémoire disponibles
  100. * look for pictures in all available memory zones
  101.     move.l    MemList(a6),a4    ;Execbase->MemList
  102. .loop    tst.l    (a4)
  103.     beq.s    .done        ;no more memory zone
  104.     move.l    MH_LOWER(a4),lastadr(a5)    ;memory zone lower limit
  105.     move.l    MH_UPPER(a4),himem(a5)        ;memory zone upper limit
  106.  
  107.     clr    $dff180
  108.  
  109.     move.l    a4,-(sp)
  110.     bsr.b    SearchPic    ;scan memory
  111.     move.l    (sp)+,a4
  112.     tst.l    d7        ;an error occured during last disk write?
  113.     bne.s    .err        ;if yes...
  114.                 ;if no, continue
  115.  
  116.     move.l    LN_SUCC(a4),a4    ;next memory zone
  117.     move.l    a4,d0        ;no more?
  118.     bne.s    .loop
  119. .done
  120.     move.l    hashbuf(a5),d0
  121.     beq.s    .nobuf
  122.     move.l    d0,a0
  123.     move.l    d0,-(sp)
  124.     move    numpics(a5),4(a0);nbre d'images sauvées
  125.     bsr.w    WriteHash    ;sauver hashtable (save hashtable)
  126.     move.l    (sp)+,a1
  127.     move.l    #512,d0
  128.     jsr    FreeMem(a6)    ;and free buffer
  129. .nobuf
  130.  
  131. * display results (number of pics found and saved to disk)
  132.     lea    num.txt(pc),a0
  133.     moveq    #0,d0
  134.     move    numpics(a5),d0
  135.     moveq    #$30,d1
  136.     divu    #10,d0
  137.     add.b    d1,d0
  138.     move.b    d0,(a0)+
  139.     swap    d0
  140.     add.b    d1,d0
  141.     move.b    d0,(a0)+
  142.     lea    noerr.txt(pc),a0    ;afficher le nbre d'images sauvées
  143.     bra.s    .al            ;ou si une erreur est survenue
  144. .err
  145.     lea    err.txt(pc),a0
  146. .al    bsr.w    MyAlert        ;show error message
  147. xit:
  148.     bsr.w    MotOff        ;turn drive's motor off
  149.     IFD    DBUG
  150.     move.l    ioreq(a5),a1
  151.     jsr    CloseDevice(a6)
  152.     lea    tdport(pc),a1
  153.     jsr    RemPort(a6)
  154.     ENDC
  155.  
  156.     move.l    intbase(a5),a1
  157.     jsr    CloseLibrary(a6)
  158.  
  159.     lea    VARSIZE(sp),sp    ;restore stack
  160.     movem.l    (sp)+,d0-a6    ;restore regs
  161.  
  162. * finally, boot the system (A6 already contains Execbase)
  163.     lea    dos.name(pc),a1
  164.     jsr    FindResident(a6)
  165.     move.l    d0,a0
  166.     move.l    22(a0),a0
  167.     moveq    #0,d0
  168.     rts
  169.  
  170. *** Chercher des images en mémoire & les sauver sur disk
  171. *** Search pics in memory & save to disk
  172. SearchPic:
  173.     move.l    lastadr(a5),a4        ;address of the last pic found
  174. .bcl0
  175.     lea    form.txt(pc),a0
  176.     moveq    #4-1,d0
  177. .bcl
  178.     add    #$0111,$dff180        ;un peu d'animation! (some animation)
  179.     cmp    #$fff,$dff180
  180.     bne.s    .skip
  181.     clr    $dff180
  182. .skip
  183.     cmpa.l    himem(a5),a4
  184.     bhi.s    .f
  185.     cmpm.b    (a0)+,(a4)+
  186.     bne.s    .bcl0
  187.     btst    #10,$dff016        ;RMB to skip
  188.     beq.s    .f
  189.     dbf    d0,.bcl
  190.     move.l    a4,d0
  191.     and.b    #~1,d0        ;adresse paire (even address)
  192.     move.l    d0,a4
  193.     cmp.l    #'ILBM',4(a4)
  194.     bne.s    .bcl0
  195.     cmp.l    #'BMHD',8(a4)
  196.     bne.s    .bcl0
  197.  
  198.     addq    #1,numpics(a5)    ;incrémenter compteur (numpics++)
  199.     move.l    (a4),d0        ;picture length (in bytes)
  200.     addq.l    #8,d0        ;add 8 bytes
  201.     move.l    d0,piclen(a5)
  202.     subq.l    #4,a4
  203.     move.l    a4,lastadr(a5)
  204.  
  205.     move.l    d0,d6
  206.     moveq    #9,d1
  207.     lsr.l    d1,d6        ;d6=d6/512
  208.     addq.l    #1,d6        ;nbre de blocs à sauver+1
  209.                 ;(number of blocks to save+1)
  210.  
  211.     bsr.s    WriteBlk    ;write the blocks
  212.     tst.l    d0        ;error occured?
  213.     bne.s    .write_err    ;yes!
  214.     add.l    d6,lastadr(a5)    ;no, search next pic
  215.     bra.s    SearchPic
  216. .f    moveq    #0,d7        ;return flag: no error
  217.     rts
  218. .write_err
  219.     moveq    #-1,d7        ;return flag: error
  220.     rts
  221.  
  222. * Write hashtable on disk block number 2 (length: 1 block (512 bytes))
  223. * Hashtable format is:
  224. *
  225. * offset    identifier        value
  226. *-------------------------------------------------------
  227. *    0    header            'PICS' (longword)
  228. *    4    number of pics saved    (word)
  229. *    6    disk offset of 1st pic    (longword)
  230. *    10    length of pic (in bytes)(longword)
  231. *    14    disk offset of 2nd pic    (longword)
  232. *    18    length of pic        (longword)
  233. * and so on...
  234. WriteHash:
  235.     move.l    hashbuf(a5),a4
  236.     moveq    #2,d0        ;offset=2
  237.     move.l    d0,lastblk(a5)
  238.     moveq    #1,d6        ;length=1 bloc
  239. * écrire d6 blocks à partir de l'offset d7
  240. * Write disk blocks:
  241. *    d6 contains the number of blocks to write
  242. *    d7 contains the disk offset
  243. WriteBlk:
  244.     move.l    ioreq(a5),a1
  245.     move    #3,28(a1)
  246.     move.l    a1,-(sp)
  247.     move.l    a4,40(a1)    ;io_data
  248.     move.l    d6,d0
  249.     moveq    #9,d1
  250.     lsl.l    d1,d0        ;d0=d0*512
  251.     move.l    d0,36(a1)    ;io_length
  252.     move.l    lastblk(a5),d7
  253.     add.l    d6,lastblk(a5)
  254.     move.l    d7,(a3)+    ;put offset in hash table
  255.     move.l    piclen(a5),(a3)+;piclen (in bytes)
  256.     lsl.l    d1,d7
  257.     move.l    d7,44(a1)    ;io_offset
  258.     jsr    DoIO(a6)
  259.     move.l    (sp)+,a1
  260.     move    #4,28(a1)
  261.     jmp    DoIO(a6)
  262. ;    rts
  263.  
  264. MotOff:    * stop the drive's motor
  265.     move.l    ioreq(a5),a1
  266.     move    #9,28(a1)
  267.     clr.l    36(a1)
  268.     jmp    DoIO(a6)
  269. ;    rts
  270.  
  271. * Display 'guru' alert
  272. * a0 must contain the address of the text to display
  273. MyAlert:
  274.     movem.l    d1-a6,-(sp)
  275.     moveq    #0,d0        ;alert number
  276.     moveq    #$7f,d1        ;alert height
  277.     move.l    intbase(a5),a6
  278.     jsr    DisplayAlert(a6)
  279.     movem.l    (sp)+,d1-a6
  280.     tst.l    d0
  281.     rts
  282.  
  283. dos.name    dc.b "dos.library",0
  284. intname        dc.b "intuition.library",0
  285.  
  286. ;1st 4 bytes of an IFF file
  287. form.txt    dc.b "FORM"
  288.  
  289. * Format of text:
  290. * 0,x,y,'text',0,1
  291. *     or
  292. * 0,x,y,'text',0,0 (last line of text)
  293.  
  294. alert.txt:
  295.  dc.b 0,20,20,"IFF-ILBM Ripper 1.0 by Frédéric BASSALER",0,1
  296.  dc.b 0,20,40,"Searches memory for IFF-ILBM pictures"
  297.  dc.b " & writes them on disk sectors",0,1
  298.  dc.b 0,20,50,"Use PicRestore to restore them.",0,1
  299.  dc.b 0,20,75,">> INSERT TARGET DISK <<",0,1
  300.  dc.b 0,20,90,"WARNING - All datas on disk will be lost!",0,1
  301.  dc.b 0,20,110,"Left = Search *** Right = Abort",0,0
  302.  
  303. noerr.txt     dc.b 0,20,50,"Found "
  304. num.txt         dc.b "xx pics!",0,0
  305. err.txt         dc.b 0,20,50,"Error!",0,0
  306.  
  307.     IFD    DBUG
  308. trackname dc.b    "trackdisk.device",0
  309.     even
  310. tdport    dcb.b    34,0
  311. tdreq    dcb.b    56,0
  312.     ENDC
  313.  
  314. End:
  315.     dcb.b    512*2,0
  316.